<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


</head>
<body>

    <script src="/js/jquery-3.0.0.slim.min.js"></script>
    <script src="/js/bootstrap.min.js"></script>
    <script src="/js/axios.min.js"></script>
    <script>
        $(function(){
            // 解决微信浏览器字体改变的问题
            if (typeof WeixinJSBridge == "object" && typeof WeixinJSBridge.invoke == "function") {
                handleFontSize();
            } else {
                if (document.addEventListener) {
                    document.addEventListener("WeixinJSBridgeReady", handleFontSize, false);
                } else if (document.attachEvent) {
                    document.attachEvent("WeixinJSBridgeReady", handleFontSize);
                    document.attachEvent("onWeixinJSBridgeReady", handleFontSize);
                }
            }
            function handleFontSize() {
                WeixinJSBridge.invoke('setFontSizeCallback', { 'fontSize': 0 });
                WeixinJSBridge.on('menu:setfont', function () {
                    WeixinJSBridge.invoke('setFontSizeCallback', { 'fontSize': 0 });
                });
            }

            let query = window.location.search ?  window.location.search.substring(1) : '';
            let url = "";
            if(!query){
                hideBtn();
                return;
            }
            let id = query.split("=")[1];
            if(!id){
                hideBtn();
                return;
            }
            
            getById(id);
            async function getById(id){
                let res = await axios({
                    method: "get",
                    url: "/files/getById",
                    params: {
                        id
                    }
                });
                if(!res.data.url){
                    hideBtn(id);
                    // window.location = "/blank"
                    return;
                }
                render();
                url = res.data.url;
                $("#show-btn").click(function(){ 
                    $("#show-btn").hide();
                    window.open("/pdfjs/web/viewer.html?" + url);
                })
            }
            function hideBtn(id){
                // $("#show-btn").hide();
                // $(".content").append("<p style='color: red'>没有相应的pdf文件</p>");
                window.location = "https://"+id
            }
            

            function render(){
                let html = `    
                <link rel="stylesheet" href="/css/style.css">
                <link rel="stylesheet" href="/css/bootstrap.min.css">
                <div class="container">
                    <div class="row" >
                        <div class="panel">
                            <div class="title">
                            四川CA校验结果
                            </div>
                            <div class="content">
                                <h3>二维码通过四川省数字证书认证管理中心验证，查看证明详细信息</h3>
                                <button id="show-btn" type="button" class="btn btn-info">查看详情</button>
                            </div>
                        </div>
                        
                    </div>
                </div>`
                $("body").append(html);
            }
        })
        
    </script>
</body>
</html>